import 'package:flutter/material.dart';
import 'package:seedfour/app/constants.dart';
import 'package:timeago/timeago.dart' as timeago;

class MessageItem extends StatefulWidget {
  final String title;
  final String message;
  final DateTime time;

  const MessageItem({
    super.key,
    required this.title,
    required this.time,
    required this.message,
  });

  @override
  State<StatefulWidget> createState() => _MessageItemState();
}

class _MessageItemState extends State<MessageItem> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(0, kSpaceSmall, 0, 0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Text(
            widget.title,
            style: const TextStyle(
              color: Colors.black,
              fontWeight: FontWeight.w900,
              fontSize: 16.0,
            ),
          ),
          Padding(padding: EdgeInsets.fromLTRB(0, kSpaceMini, 0, 0)),
          Row(
            children: <Widget>[
              Expanded(
                child: Text(
                  widget.message,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                  textAlign: TextAlign.left,
                  style: const TextStyle(
                    color: Colors.black87,
                  ),
                ),
              ),
              Text(
                timeago.format(widget.time, locale: 'zh_CN'),
                textAlign: TextAlign.right,
                style: const TextStyle(
                  color: Colors.black54,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }
}
